//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "MakeCms.h"
using namespace Cephei::QL::Instruments;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Indexes/SwapIndex.h>
#include <gen/QL/Indexes/IborIndex.h>
#include <gen/QL/Instruments/Swap.h>
#include <gen/QL/Cashflows/CmsCouponPricer.h>
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL::Cashflows;
using namespace Cephei::QL::Termstructures;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Instruments::CMakeCms::CMakeCms (Cephei::QL::Times::IPeriod^ swapTenor, Cephei::QL::Indexes::ISwapIndex^ swapIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ iborSpread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ forwardStart) 
{
	_pSpinlock = new boost::detail::spinlock ();
    CPeriod^ _CswapTenor;
    CSwapIndex^ _CswapIndex;
    CPeriod^ _CforwardStart;
    try
    {
#ifdef HANDLE
        _phMakeCms = NULL;
#endif
        _CswapTenor = safe_cast<CPeriod^> (swapTenor);
        _CswapTenor->Lock();
        QuantLib::Period& _swapTenor = static_cast<QuantLib::Period&> (_CswapTenor->GetReference ()); 
        _CswapIndex = safe_cast<CSwapIndex^> (swapIndex);
        _CswapIndex->Lock();
        boost::shared_ptr<QuantLib::SwapIndex>& _swapIndex = static_cast<boost::shared_ptr<QuantLib::SwapIndex>&> (_CswapIndex->GetShared ()); 
        QuantLib::Spread _iborSpread = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (iborSpread) ? (QuantLib::Spread)ValueHelper::Convert (iborSpread->Value) : 0.0); //4
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (forwardStart))
        {
            _CforwardStart = safe_cast<CPeriod^> (forwardStart->Value);
            _CforwardStart->Lock();
        }
        QuantLib::Period& _forwardStart = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (forwardStart) ? static_cast<QuantLib::Period&> (_CforwardStart->GetReference ()) : 0*Days); //1
        _ppMakeCms = new boost::shared_ptr<QuantLib::MakeCms> (new QuantLib::MakeCms ( _swapTenor,  _swapIndex,  _iborSpread,  _forwardStart ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_CswapTenor != nullptr) _CswapTenor->Unlock();
        if (_CswapIndex != nullptr) _CswapIndex->Unlock();
        if (_CforwardStart != nullptr) _CforwardStart->Unlock();
    }
}
Cephei::QL::Instruments::CMakeCms::CMakeCms (Cephei::QL::Times::IPeriod^ swapTenor, Cephei::QL::Indexes::ISwapIndex^ swapIndex, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ iborSpread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ forwardStart) 
{
	_pSpinlock = new boost::detail::spinlock ();
    CPeriod^ _CswapTenor;
    CSwapIndex^ _CswapIndex;
    CIborIndex^ _CiborIndex;
    CPeriod^ _CforwardStart;
    try
    {
#ifdef HANDLE
        _phMakeCms = NULL;
#endif
        _CswapTenor = safe_cast<CPeriod^> (swapTenor);
        _CswapTenor->Lock();
        QuantLib::Period& _swapTenor = static_cast<QuantLib::Period&> (_CswapTenor->GetReference ()); 
        _CswapIndex = safe_cast<CSwapIndex^> (swapIndex);
        _CswapIndex->Lock();
        boost::shared_ptr<QuantLib::SwapIndex>& _swapIndex = static_cast<boost::shared_ptr<QuantLib::SwapIndex>&> (_CswapIndex->GetShared ()); 
        _CiborIndex = safe_cast<CIborIndex^> (iborIndex);
        _CiborIndex->Lock();
        boost::shared_ptr<QuantLib::IborIndex>& _iborIndex = static_cast<boost::shared_ptr<QuantLib::IborIndex>&> (_CiborIndex->GetShared ()); 
        QuantLib::Spread _iborSpread = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (iborSpread) ? (QuantLib::Spread)ValueHelper::Convert (iborSpread->Value) : 0.0); //4
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (forwardStart))
        {
            _CforwardStart = safe_cast<CPeriod^> (forwardStart->Value);
            _CforwardStart->Lock();
        }
        QuantLib::Period& _forwardStart = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (forwardStart) ? static_cast<QuantLib::Period&> (_CforwardStart->GetReference ()) : 0*Days); //1
        _ppMakeCms = new boost::shared_ptr<QuantLib::MakeCms> (new QuantLib::MakeCms ( _swapTenor,  _swapIndex,  _iborIndex,  _iborSpread,  _forwardStart ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_CswapTenor != nullptr) _CswapTenor->Unlock();
        if (_CswapIndex != nullptr) _CswapIndex->Unlock();
        if (_CiborIndex != nullptr) _CiborIndex->Unlock();
        if (_CforwardStart != nullptr) _CforwardStart->Unlock();
    }
}
Cephei::QL::Instruments::CMakeCms::CMakeCms (boost::shared_ptr<QuantLib::MakeCms>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMakeCms = NULL;
#endif
	_ppMakeCms = &childNative;
    
}
Cephei::QL::Instruments::CMakeCms::CMakeCms (QuantLib::MakeCms& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phMakeCms = NULL;
#endif
	_ppMakeCms = new boost::shared_ptr<QuantLib::MakeCms> (&childNative);
    
    _MakeCmsOwner = owner;
    
}

Cephei::QL::Instruments::CMakeCms::CMakeCms (CMakeCms^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMakeCms = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppMakeCms = new boost::shared_ptr<QuantLib::MakeCms> (copy->GetShared());
        
    }
}
Cephei::QL::Instruments::CMakeCms::CMakeCms (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMakeCms = NULL;
#endif
	if (!t->IsSubclassOf(CMakeCms::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::CMakeCms::CMakeCms (QuantLib::Handle<QuantLib::MakeCms>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phMakeCms = &childNative;
	_ppMakeCms = &static_cast<boost::shared_ptr<QuantLib::MakeCms>>(childNative.currentLink());
    
    _MakeCmsOwner = owner;
}
Cephei::QL::Instruments::CMakeCms::CMakeCms (QuantLib::Handle<QuantLib::MakeCms> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phMakeCms = &childNative;
	_ppMakeCms = &static_cast<boost::shared_ptr<QuantLib::MakeCms>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::CMakeCms::CMakeCms (QuantLib::MakeCms childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMakeCms = NULL;
#endif
	_ppMakeCms = new boost::shared_ptr<QuantLib::MakeCms> (new QuantLib::MakeCms (childNative));
    
}
#endif

Cephei::QL::Instruments::CMakeCms::~CMakeCms ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppMakeCms != NULL)
    {
	    delete _ppMakeCms;
        _ppMakeCms = NULL;
    }
}
Cephei::QL::Instruments::CMakeCms::!CMakeCms ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppMakeCms != NULL)
    {
	    delete _ppMakeCms;
    }
}
QuantLib::MakeCms& Cephei::QL::Instruments::CMakeCms::GetReference ()
{
    if (_ppMakeCms == NULL) throw REFNEW NativeNullException ();
	return **_ppMakeCms;
}
boost::shared_ptr<QuantLib::MakeCms>& Cephei::QL::Instruments::CMakeCms::GetShared ()
{
    if (_ppMakeCms == NULL) throw REFNEW NativeNullException ();
	return *_ppMakeCms;
}
QuantLib::MakeCms* Cephei::QL::Instruments::CMakeCms::GetPointer ()
{
    if (_ppMakeCms == NULL) throw REFNEW NativeNullException ();
	return &**_ppMakeCms;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::MakeCms>& Cephei::QL::Instruments::CMakeCms::GetHandle ()
{
	if (_phMakeCms == NULL)
	{
		_phMakeCms = new Handle<QuantLib::MakeCms> (*_ppMakeCms);
	}
	return *_phMakeCms;
}
#endif
bool Cephei::QL::Instruments::CMakeCms::HasNative () 
{
	return (_ppMakeCms != NULL);
}

Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::ReceiveCms (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        bool _flag = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (flag) ? (bool)ValueHelper::Convert (flag->Value) : true); //9a
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->receiveCms ( _flag );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithAtmSpread (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        bool _flag = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (flag) ? (bool)ValueHelper::Convert (flag->Value) : true); //9a
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withAtmSpread ( _flag );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithCmsCouponPricer (Cephei::QL::Cashflows::ICmsCouponPricer^ couponPricer)
{
    CCmsCouponPricer^ _CcouponPricer;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _CcouponPricer = safe_cast<CCmsCouponPricer^> (couponPricer);
        _CcouponPricer->Lock();
        boost::shared_ptr<QuantLib::CmsCouponPricer>& _couponPricer = static_cast<boost::shared_ptr<QuantLib::CmsCouponPricer>&> (_CcouponPricer->GetShared ()); 
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withCmsCouponPricer ( _couponPricer );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_CcouponPricer != nullptr) _CcouponPricer->Unlock();
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithCmsLegCalendar (Cephei::QL::Times::ICalendar^ cal)
{
    CCalendar^ _Ccal;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Ccal = safe_cast<CCalendar^> (cal);
        _Ccal->Lock();
        QuantLib::Calendar& _cal = static_cast<QuantLib::Calendar&> (_Ccal->GetReference ()); 
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withCmsLegCalendar ( _cal );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ccal != nullptr) _Ccal->Unlock();
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithCmsLegConvention (QL::Times::BusinessDayConventionEnum bdc)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::BusinessDayConvention _bdc = (QuantLib::BusinessDayConvention)bdc ;
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withCmsLegConvention ( _bdc );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithCmsLegDayCount (Cephei::QL::Times::IDayCounter^ dc)
{
    CDayCounter^ _Cdc;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Cdc = safe_cast<CDayCounter^> (dc);
        _Cdc->Lock();
        QuantLib::DayCounter& _dc = static_cast<QuantLib::DayCounter&> (_Cdc->GetReference ()); 
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withCmsLegDayCount ( _dc );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cdc != nullptr) _Cdc->Unlock();
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithCmsLegEndOfMonth (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        bool _flag = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (flag) ? (bool)ValueHelper::Convert (flag->Value) : true); //9a
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withCmsLegEndOfMonth ( _flag );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithCmsLegFirstDate (DateTime d)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d); //a
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withCmsLegFirstDate ( _d );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithCmsLegNextToLastDate (DateTime d)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d); //a
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withCmsLegNextToLastDate ( _d );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithCmsLegRule (QL::Times::DateGeneration::RuleEnum r)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::DateGeneration::Rule _r = (QuantLib::DateGeneration::Rule)r ;
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withCmsLegRule ( _r );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithCmsLegTenor (Cephei::QL::Times::IPeriod^ t)
{
    CPeriod^ _Ct;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Ct = safe_cast<CPeriod^> (t);
        _Ct->Lock();
        QuantLib::Period& _t = static_cast<QuantLib::Period&> (_Ct->GetReference ()); 
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withCmsLegTenor ( _t );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ct != nullptr) _Ct->Unlock();
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithCmsLegTerminationDateConvention (QL::Times::BusinessDayConventionEnum bdc)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::BusinessDayConvention _bdc = (QuantLib::BusinessDayConvention)bdc ;
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withCmsLegTerminationDateConvention ( _bdc );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithDiscountingTermStructure (Cephei::QL::Termstructures::IYieldTermStructure^ discountingTermStructure)
{
    CYieldTermStructure^ _CdiscountingTermStructure;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _CdiscountingTermStructure = safe_cast<CYieldTermStructure^> (discountingTermStructure);
        _CdiscountingTermStructure->Lock();
        Handle<QuantLib::YieldTermStructure>& _discountingTermStructure = static_cast<Handle<QuantLib::YieldTermStructure>&> (_CdiscountingTermStructure->GetHandle ()); 
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withDiscountingTermStructure ( _discountingTermStructure );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_CdiscountingTermStructure != nullptr) _CdiscountingTermStructure->Unlock();
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithEffectiveDate (DateTime effectiveDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _effectiveDate = (QuantLib::Date)ValueHelper::Convert (effectiveDate); //a
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withEffectiveDate ( _effectiveDate );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithFloatingLegCalendar (Cephei::QL::Times::ICalendar^ cal)
{
    CCalendar^ _Ccal;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Ccal = safe_cast<CCalendar^> (cal);
        _Ccal->Lock();
        QuantLib::Calendar& _cal = static_cast<QuantLib::Calendar&> (_Ccal->GetReference ()); 
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withFloatingLegCalendar ( _cal );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ccal != nullptr) _Ccal->Unlock();
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithFloatingLegConvention (QL::Times::BusinessDayConventionEnum bdc)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::BusinessDayConvention _bdc = (QuantLib::BusinessDayConvention)bdc ;
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withFloatingLegConvention ( _bdc );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithFloatingLegDayCount (Cephei::QL::Times::IDayCounter^ dc)
{
    CDayCounter^ _Cdc;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Cdc = safe_cast<CDayCounter^> (dc);
        _Cdc->Lock();
        QuantLib::DayCounter& _dc = static_cast<QuantLib::DayCounter&> (_Cdc->GetReference ()); 
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withFloatingLegDayCount ( _dc );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cdc != nullptr) _Cdc->Unlock();
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithFloatingLegEndOfMonth (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        bool _flag = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (flag) ? (bool)ValueHelper::Convert (flag->Value) : true); //9a
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withFloatingLegEndOfMonth ( _flag );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithFloatingLegFirstDate (DateTime d)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d); //a
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withFloatingLegFirstDate ( _d );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithFloatingLegNextToLastDate (DateTime d)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d); //a
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withFloatingLegNextToLastDate ( _d );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithFloatingLegRule (QL::Times::DateGeneration::RuleEnum r)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::DateGeneration::Rule _r = (QuantLib::DateGeneration::Rule)r ;
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withFloatingLegRule ( _r );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithFloatingLegTenor (Cephei::QL::Times::IPeriod^ t)
{
    CPeriod^ _Ct;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Ct = safe_cast<CPeriod^> (t);
        _Ct->Lock();
        QuantLib::Period& _t = static_cast<QuantLib::Period&> (_Ct->GetReference ()); 
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withFloatingLegTenor ( _t );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ct != nullptr) _Ct->Unlock();
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithFloatingLegTerminationDateConvention (QL::Times::BusinessDayConventionEnum bdc)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::BusinessDayConvention _bdc = (QuantLib::BusinessDayConvention)bdc ;
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withFloatingLegTerminationDateConvention ( _bdc );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms::WithNominal (Double n)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Real _n = (QuantLib::Real)ValueHelper::Convert (n); //a
    	QuantLib::MakeCms& _rv = (QuantLib::MakeCms&)(*_ppMakeCms)->withNominal ( _n );   
        Cephei::QL::Instruments::CMakeCms^ _nrv = REFNEW Cephei::QL::Instruments::CMakeCms (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms_Factory::Create (Cephei::QL::Times::IPeriod^ swapTenor, Cephei::QL::Indexes::ISwapIndex^ swapIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ iborSpread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ forwardStart)
{
    return REFNEW CMakeCms ( swapTenor,  swapIndex,  iborSpread,  forwardStart);
}
Cephei::QL::Instruments::IMakeCms^ Cephei::QL::Instruments::CMakeCms_Factory::Create (Cephei::QL::Times::IPeriod^ swapTenor, Cephei::QL::Indexes::ISwapIndex^ swapIndex, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ iborSpread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ forwardStart)
{
    return REFNEW CMakeCms ( swapTenor,  swapIndex,  iborIndex,  iborSpread,  forwardStart);
}
